package lee.vioson.ebook.ui

import androidx.navigation.NavHostController

/**
 *Author:viosonlee
 *Date:2023/6/2
 *DESCRIPTION:
 */

object AppDestinations {
    const val MAIN_ROUTE = "main"
    const val SEARCH_ROUTE = "search"
    const val LOGIN_ROUTE = "login"
    const val REGISTER_ROUTE = "register"
    const val SET_PASSWORD_ROUTE = "set_password"
    const val OTP_VERIFICATION_ROUTE =
        "otp_verification?${Constants.email}={${Constants.email}}&${Constants.password}={${Constants.password}}&${Constants.type}={${Constants.type}}"
    const val BOOK_DETAIL_ROUTE = "book_detail/{${Constants.bookId}}"
    const val READ_ROUTE = "read"
    const val PURCHASE_HISTORY = "purchase_history"
    const val FEEDBACK = "feedback/{${Constants.msgId}}"
    const val FEEDBACK_DETAIL = "feedback_detail/{${Constants.msgId}}"
    const val FEEDBACK_HISTORY = "feedback_history"
    const val VIP_SCREEN = "vip_subscribe"
    fun withArguments(route: String, arguments: Map<String, String>): String {
        var routeString = route
        arguments.keys.forEach { key ->
            if (routeString.contains("{$key}")) {
                routeString = routeString.replace("{$key}", arguments[key] ?: "")
            }
        }
        return routeString
    }

    fun withPath(route: String, pathName: String, path: String): String {
        var routeString = route
        if (routeString.contains("{$pathName}")) {
            routeString = routeString.replace("{$pathName}", path)
        }
        return routeString
    }
}

fun NavHostController.navigate(route: String, arguments: Map<String, String>) {
    var routeString = route
    arguments.keys.forEach { key ->
        if (routeString.contains("{$key}")) {
            routeString = routeString.replace("{$key}", arguments[key] ?: "")
        }
    }
    navigate(routeString)
}


object Constants {
    const val email = "email"
    const val password = "password"
    const val type = "type"
    const val bookId = "bookId"
    const val msgId = "msgId"
}